<?php

namespace app\official\controller;

use think\Controller;
// 微信公众号封装类
use EasyWeChat\Factory;
// 微信公众号配置
use addons\wechat\library\Config;

class Menu extends Controller
{
    // 微信属性
    protected $WeChat = null;

    public function __construct()
    {
        parent::__construct();

        $this->WeChat = Factory::officialAccount(Config::load());
    }

    public function create()
    {
        $buttons = [
            [
                "type" => "click",
                "name" => "今日歌曲",
                "key"  => "V1001_TODAY_MUSIC"
            ],
            [
                "name"       => "菜单",
                "sub_button" => [
                    [
                        "type" => "view",
                        "name" => "搜索",
                        "url"  => "http://www.soso.com/"
                    ],
                    [
                        "type" => "view",
                        "name" => "视频",
                        "url"  => "http://v.qq.com/"
                    ],
                    [
                        "type" => "click",
                        "name" => "赞一下我们",
                        "key" => "V1001_GOOD"
                    ],
                ],
            ],
        ];

        $result = $this->WeChat->menu->create($buttons);

        if ($result) {
            echo '创建成功';
        } else {
            echo '创建失败';
        }
    }
}
